package com.discuz.post;

import java.io.IOException;
import java.net.MalformedURLException;
import com.discuz.spider.WebClientAgent;
import com.discuz.spider.jpkoo.Utils;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextArea;

public class AutoReply {

	public static HtmlPage autoReply(String postURL)
			throws FailingHttpStatusCodeException, MalformedURLException,
			IOException, InterruptedException {
		
		WebClient client = WebClientAgent.get();

		HtmlPage postPage = client.getPage(postURL);

		HtmlAnchor reply = (HtmlAnchor) postPage
				.getFirstByXPath("//*[@class='locked']/a[1]");

		// must reply
		if (reply != null) {
			System.out.println("must reply post....");

			Thread.sleep(5000);
			HtmlPage rp = reply.click();

			HtmlTextArea text = rp.getFirstByXPath("id('e_textarea')");
			if (text == null) {
				text = rp.getFirstByXPath("id('postmessage')");
				HtmlButton btn = rp.getFirstByXPath("id('postsubmit')");

				if (text != null && btn != null) {
					text.blur();
					text.setText(randomReply());
					btn.click();
					Thread.sleep(1000);
					postPage = client.getPage(postURL);
				}
			}

		} else {
			System.out.println("not must reply post");
		}
		
		return postPage;
	}
	
	 private  static String [] reply={
		  "我是忠实粉丝。。",
		  "谢谢楼主的分享",
		  "真的够促性了，慢好，哈哈",
		  "看到黑丝就硬了",
		  "感谢分享 楼主辛苦了",
		  "拍得好,谢谢楼主的分享",
		  "楼主好艳福啊~这个情景不是那么容易见得·",
		  "支持支持支持支持支持支持支持支持支持支持",
		  "支持楼主哈，楼主继续加油咯",
		  "感谢楼主的分享，支持原创，新手敬上",
		  "这丝袜太性感了 很诱惑啊",
		  "先顶后看养成好习惯，楼主辛苦了！",
		  "太有个性了，值得欣赏",
		  "请选择您此刻的心情图片并写下今天最想说的话",
		  "我好喜欢啊，好性感啊，喜欢",
		  "好惹火的身材啊 很霸道 我喜欢",
		  "谢谢楼主分享这么给力",
		  "这样也可以啊性感给力不 来点给力的吧",
		  "太风骚了，保养得不错。太开放了",
		  "特写都有了，极品"};
	
	  public static String randomReply(){
		  
		  return reply[Utils.generaterRM(0,19)];
	  }

}
